#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool hasGroupsSizeX(vector<int>& deck) {
        unordered_map<int, int> hash;
        for (auto& e : deck) hash[e]++;

        int min_count = 0x3f3f3f3f;
        for (auto& [a, b] : hash) min_count = min(min_count, b);

        if (min_count == 1)
            return false;

        int flag = 1;
        for (int i = 2; i <= min_count; ++i)
        {
            flag = 1;
            for (auto& [a, b] : hash)
            {
                if (b % i != 0)
                {
                    flag = 0;
                    break;
                }
            }

            if (flag)
                return true;
        }

        return false;
    }
};